package com.ymatou.iapi.productitem.testcase;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productitem.service.GetProductDescriptionByProductIdCall;
import com.ymatou.iapi.productitem.service.GetProductInfoByProductIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.database.mongo.ProductDescriptionInfoWapper;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.utils.EnvSetup;

public class Ts_GetProductDescriptionByProductId {
	private static String sellerName = EnvSetup.getData("productsellername");
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据商品ID,查询商品描述信息");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new GetProductInfoByProductIdCall().getOpurl());
	}
	
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductDescriptionByProductId() {
		Logger.start(true, "根据商品ID,查询商品描述信息");
		try{
			//Map<String,String> tgtAndActKeyPaths = new HashMap<String,String>();
			
			Set<String> keyPathsSet =  new HashSet<String>();
			//1 add new product
			String productId = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, null).getJSONObject("Data").getString("ProductID");			
			
			JSONObject requestBean = GetProductDescriptionByProductIdCall.GetProductDescriptionByProductId(productId);
			Logger.verifyEquals(200, requestBean.getInt("Code"), "响应报文-返回码");
			 
			JSONObject productDescBean = requestBean.getJSONObject("Data").getJSONObject("Description");
			AssertService.assertResultContain(productDescBean, Arrays.asList("ProductId","AttributeList","Description","IsNewDesc"));
			
			
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				Map<String, Object> productDescriptionInfoMap =  new ProductDescriptionInfoWapper().getByProductId(productId);
				keyPathsSet.add("ProductId");
				keyPathsSet.add("Description");
				AssertService.assertResultEqual(keyPathsSet,productDescriptionInfoMap,productDescBean);
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				//check Mongo3x...
			}
			
	
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
}















